package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;

    //物资去处列表  分页带条件
    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(@RequestParam Map<String,Object> queryMap){
        PageVO<ConsumerVO> consumerList = consumerService.findConsumerList(queryMap);
        return ResponseBean.success(consumerList);
    }
    //添加物资去处
    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated ConsumerVO consumerVO){
        consumerService.add(consumerVO);
        return ResponseBean.success();
    }
    //编辑物资去处
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ConsumerVO consumerVO = consumerService.edit(id);
        return ResponseBean.success(consumerVO);
    }
    //更新
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestParam ConsumerVO consumerVO){
        consumerService.update(id,consumerVO);
        return ResponseBean.success();
    }
    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        consumerService.delete(id);
        return ResponseBean.success();
    }
    //获取所有已知去向的出库记录
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<ConsumerVO> consumerVOList = consumerService.findAll();
        return ResponseBean.success(consumerVOList);
    }



}
